package com.example.myproject.controller;

import com.example.myproject.dto.CommonResponse;
import com.example.myproject.dto.rating.RatingRequest;
import com.example.myproject.dto.rating.RatingResponse;
import com.example.myproject.security.JwtAuthenticationFilter;
import com.example.myproject.service.RatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/values/ratings")
public class RatingController {

    @Autowired
    private RatingService ratingService;

    @PostMapping
    public CommonResponse<RatingResponse> submitRating(
            @AuthenticationPrincipal JwtAuthenticationFilter.UserPrincipal principal,
            @RequestBody RatingRequest req) {
        // 校验用户是否登录
        if (principal == null) {
            return CommonResponse.fail("请先登录");
        }

        // 如果需要校验新手考核，可以在这里加
        // if (!principal.isPassedNoviceExam()) {
        //     return CommonResponse.fail("请先通过新手考核");
        // }

        RatingResponse resp = ratingService.submitRating(req);
        return CommonResponse.success(resp);
    }
}